function loadBody() {

	// Creazione DataSource
	ds[0] = new DataSource (crescentina);
	ds[1] = new DataSource (sDiIntDS);
	ds[2] = new DataSource (ferrazzDS);
	ds[3] = new DataSource (cataDS);

	// Creazione DataFormatter
	curDF = 0;
	df[0] = new DataFormatter (piadina);
	df[1] = new DataFormatter (sDiIntDF);
	df[2] = new DataFormatter (ferrazzDF);
	df[3] = new DataFormatter (cataDF);
	df[4] = new DataFormatter (tigella);

	// Creazione ContentManager
	cm = new ContentManager ();

	cm.reset ();
	
	
	/*Work Inspector*/
	workInspector = new WorkInspector(null);
}


function serialize (element) {
	var xs = new XMLSerializer();
	return xs.serializeToString (element);
}


function nodeList2CommaLista (nodeList) {
	var stringazza = "";
	for (var i = 0; i < nodeList.length - 1; i++) {
		stringazza += nodeList[i].textContent + ",";
	}

	stringazza += nodeList[i].textContent;

	return stringazza;
}


function getIndexByCatalog (url) {
	for (var i = 0; i < ds.length; i++)
		if (ds[i].publisher == url)
			return i;
	assert (false, "Non diciamo minchiate");
}


function stripNSPrefix (oldDOM) {
	var newDOM = createDOM (oldDOM.documentElement.localName, "");

	for (var i = 0; i < oldDOM.documentElement.childNodes.length; i++)
		newDOM.documentElement.appendChild (newDOM.importNode (oldDOM.documentElement.childNodes[i], true));

	return newDOM;
}


function assert (assertion, msg) {
	if (!assertion) {
		alert ("assert: " + msg);
		throw ("abort");
	}
}

function abortPoli(msg) {
	alert("Poliwiki aborted!\n\n" + msg);
	throw("Poliwiki Aborted");
}

function AjaxManager (url, callbackWait, callbackOK, callbackErr) {
	var req = init();
	req.onreadystatechange = processRequest;

	url = proxerize (url);

	// Metodi privati

	function init() {
		if (window.XMLHttpRequest){
			ajax = new XMLHttpRequest();
			if(ajax.overrideMimeType)
				ajax.overrideMimeType('text/xml');
		}else if (window.ActiveXObject){
			try {
				ajax = new ActiveXObject("Msxml2.XMLHTTP");
			}catch (e){
				try{
					ajax = new ActiveXObject("Microsoft.XMLHTTP");
				}catch (e) {
					alert('e mo che famo'+ e.message);
					return false;
				}
			}
		}
		return ajax;
	}
	
	function processRequest () {
		if (req.readyState == 4) {
			if (req.status == 200) {
				if (callbackOK) {
					callbackOK (req);
				}
			} else if (callbackErr) {
				callbackErr (req);
			}
		} else if (callbackWait) {
			callbackWait (req);
		}
	}

	// Metodi pubblici

	this.head = function() {
		req.open("HEAD", url, true);
		req.send(null);
	}

	this.get = function() {
		req.open("GET", url, true);
		req.send(null);
	}

	this.post = function(body) {
		req.open ("POST", url, true);
		req.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
		req.setRequestHeader ("Content-length", body.length);
		req.send (body);
	}
}


/*
 * Crea un DOM Document
 * ritorna false se non si riesce a creare niente
*/
function createDOM(name,ns){
	if(ns==undefined||ns==null){
		ns="";
	}
	return document.implementation.createDocument(ns, name, null);
}

/*
 * Crea un parser DOM 
 * ritorna false se non si riesce a creare niente
 */
function createParser(input){
	if(window.DOMParser){
		parser= new DOMParser();
		return parser.parseFromString(input,"text/xml");
	}else{
		if(window.ActiveXObject){
			parser=new ActiveXObject("Microsoft.XMLDOM"); 
			parser.async="false";
			parser.loadXML(input);
			return parser;
		}else{
			alert("some problems");
		}
	}	
}

/**
 * Trasforma l'URI secondo la tecnica di "proxy" utilizzata
 * @param {URI} uri URI da trasformare
 * @return {URI} URI trasformata
 */
function proxerize (uri) {
	return diomio + "proxy" + uri.substring(6);
}

/**
 * Permette di effettuare una transformazioni xslt
 * se destDOM e' null permette di formattare un document 
 */
function xslTransform (xmlDOM, xslDOM, destDOM) {
	var output;

	if (window.XSLTProcessor) {
		var xp =new XSLTProcessor();
		xp.importStylesheet(xslDOM);
		
		if (destDOM == undefined || destDOM == null)
			output = xp.transformToDocument(xmlDOM);
		else
			output = xp.transformToFragment (xmlDOM, destDOM);
	} else if (window.ActiveXObject) {
		xslp = xslt.createProcessor();
      	xslp.input = xmlDOM;
      	xslp.transform();
      	output=xslp.output;
	} else {
		assert (false, "xslTransform: non c'e' trippa per gatti");
	}

	return output;
}

